package com.mccree.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        //创建文件输入流
        File file = new File("D:\\临时\\netty文件\\file02.txt");
        FileInputStream fileInputStream = new FileInputStream(file);

        //获得对应的channel--》实际类型FileChannelImpl
        FileChannel fileChannel = fileInputStream.getChannel();


        //创建缓冲区
        ByteBuffer byteBuffer = ByteBuffer.allocate(((int) file.length()));


        //将channel的数据写入到缓冲区
        fileChannel.read(byteBuffer);

        //打印到控制台
        System.out.println(new String(byteBuffer.array()));
        fileInputStream.close();
    }
}
